package fr.jibhaine.synth
{
	import flash.utils.Dictionary;
	
	public class KeyFrequencies
	{
		private static var instance:KeyFrequencies;

		private var tab:Dictionary;
				
		public function KeyFrequencies()
		{
			//initialise les valeurs des fréquences pour chaque note
			tab = new Dictionary();
			tab["A_0"]= 27.500000000000000;
			tab["A#0"]= 29.135235094880619;
			tab["B_0"]= 30.867706328507756;
			tab["C_1"]= 32.703195662574829;
			tab["C#1"]= 34.647828872109012;
			tab["D_1"]= 36.708095989675945;
			tab["D#1"]= 38.890872965260113;
			tab["E_1"]= 41.203444614108741;
			tab["F_1"]= 43.653528929125485;
			tab["F#1"]= 46.249302838954299;
			tab["G_1"]= 48.999429497718661;
			tab["G#1"]= 51.913087197493142;
			tab["A_1"]= 55.000000000000000;
			tab["A#1"]= 58.270470189761239;
			tab["B_1"]= 61.735412657015513;
			tab["C_2"]= 65.406391325149658;
			tab["C#2"]= 69.295657744218024;
			tab["D_2"]= 73.416191979351890;
			tab["D#2"]= 77.781745930520227;
			tab["E_2"]= 82.406889228217482;
			tab["F_2"]= 87.307057858250971;
			tab["F#2"]= 92.498605677908599;
			tab["G_2"]= 97.998858995437323;
			tab["G#2"]=103.826174394986284;
			tab["A_2"]=110.000000000000000;
			tab["A#2"]=116.540940379522479;
			tab["B_2"]=123.470825314031027;
			tab["C_3"]=130.812782650299317;
			tab["C#3"]=138.591315488436048;
			tab["D_3"]=146.832383958703780;
			tab["D#3"]=155.563491861040455;
			tab["E_3"]=164.813778456434964;
			tab["F_3"]=174.614115716501942;
			tab["F#3"]=184.997211355817199;
			tab["G_3"]=195.997717990874647;
			tab["G#3"]=207.652348789972569;
			tab["A_3"]=220.000000000000000;
			tab["A#3"]=233.081880759044958;
			tab["B_3"]=246.941650628062055;
			tab["C_4"]=261.625565300598634;
			tab["C#4"]=277.182630976872096;
			tab["D_4"]=293.664767917407560;
			tab["D#4"]=311.126983722080910;
			tab["E_4"]=329.627556912869929;
			tab["F_4"]=349.228231433003884;
			tab["F#4"]=369.994422711634398;
			tab["G_4"]=391.995435981749294;
			tab["G#4"]=415.304697579945138;
			tab["A_4"]=440.000000000000000;
			tab["A#4"]=466.163761518089916;
			tab["B_4"]=493.883301256124111;
			tab["C_5"]=523.251130601197269;
			tab["C#5"]=554.365261953744192;
			tab["D_5"]=587.329535834815120;
			tab["D#5"]=622.253967444161821;
			tab["E_5"]=659.255113825739859;
			tab["F_5"]=698.456462866007768;
			tab["F#5"]=739.988845423268797;
			tab["G_5"]=783.990871963498588;
			tab["G#5"]=830.609395159890277;
			tab["A_5"]=880.000000000000000;
			tab["A#5"]=932.327523036179832;
			tab["B_5"]=987.766602512248223;
			tab["C_6"]=1046.502261202394538;
			tab["C#6"]=1108.730523907488384;
			tab["D_6"]=1174.659071669630241;
			tab["D#6"]=1244.507934888323642;
			tab["E_6"]=1318.510227651479718;
			tab["F_6"]=1396.912925732015537;
			tab["F#6"]=1479.977690846537595;
			tab["G_6"]=1567.981743926997176;
			tab["G#6"]=1661.218790319780554;
			tab["A_6"]=1760.000000000000000;
			tab["A#6"]=1864.655046072359665;
			tab["B_6"]=1975.533205024496447;
			tab["C_7"]=2093.004522404789077;
			tab["C#7"]=2217.461047814976769;
			tab["D_7"]=2349.318143339260482;
			tab["D#7"]=2489.015869776647285;
			tab["E_7"]=2637.020455302959437;
			tab["F_7"]=2793.825851464031075;
			tab["F#7"]=2959.955381693075191;
			tab["G_7"]=3135.963487853994352;
			tab["G#7"]=3322.437580639561108;
			tab["A_7"]=3520.000000000000000;
			tab["A#7"]=3729.310092144719331;
			tab["B_7"]=3951.066410048992894;
			tab["C_8"]=4186.009044809578154;
		}
		
		public static function getInstance():KeyFrequencies{
			if (instance==null) instance = new KeyFrequencies();
			
			return instance;
		}
		
		public function getFrequency(note:String):Number{
			return tab[note];
		}
	}
}